package com.hp.exception;


import com.hp.enums.ExceptionCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * @descriptions: 业务异常
 * @author: hp
 */
public class ServiceException extends RuntimeException {

    private ExceptionCode errorCode;

    public ServiceException(ExceptionCode errorCode) {
        this.errorCode = errorCode;
    }

    public ServiceException(String message, ExceptionCode errorCode) {
        super(message);
        this.errorCode = errorCode;
    }

    public ServiceException(String message, Throwable cause, ExceptionCode errorCode) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public ServiceException(ExceptionCode errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }

    public ServiceException(ExceptionCode errorCode, Throwable cause, String message) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public ExceptionCode getErrorCode() {
        return errorCode;
    }

    public ServiceException setErrorCode(ExceptionCode errorCode) {
        this.errorCode = errorCode;
        return this;
    }


    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(errorCode, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
